import java.io.IOException;

public class MiniChessAI {

	public char gameType='O';
	public String id="6737";
	public char color='W';

	public static void main(String[] args) throws IOException {

		Move move;
		State state = new State();
		Client client = new Client("imcs.svcs.cs.pdx.edu", "3589", "teamawesome", "awesome");
		MiniChessAI ai = new MiniChessAI();

		if(ai.gameType=='A')
			ai.color=client.accept(ai.id, ai.color);
		if(ai.gameType=='O')
			ai.color=client.offer(ai.color);
		if(ai.color=='B'){
			move=new Move(client.getMove());
			System.out.println(state.onMove + " Move #" + state.moveNum + ": " + move.toString());
			System.out.println("#############################################");
			state.move(move);
			System.out.println(state.toString());
			System.out.println("#############################################");
			System.out.println("#############################################");
		}
		do{
			move=state.getBetterMove();
			System.out.println(state.onMove + " Move #" + state.moveNum + ": " + move.toString());
			System.out.println("#############################################");
			state.move(move);
			client.sendMove(move.toString());
			System.out.println(state.toString());
			System.out.println("#############################################");
			System.out.println("#############################################");

			move=new Move(client.getMove());
			System.out.println(state.onMove + " Move #" + state.moveNum + ": " + move.toString());
			System.out.println("#############################################");
			state.move(move);
			System.out.println(state.toString());			
			System.out.println("#############################################");
			System.out.println("#############################################");
		}while(10000>Math.abs(state.stateValue()) && state.moveNum<41);
		client.close();
	}
}// endclass
